﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
using DataAccess;

/// <summary>
/// Summary description for Category
/// </summary>
public class CategoryDAL
{
	public CategoryDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public bool Insert(Category category)
    {
        bool result = false;
        DbCommand cmd = GenericData.CreateCommand();
        cmd.CommandText = "INSERT INTO Category(CategoryName, Description) VALUES('" + category.CategoryName + "', '" + category.Description + "')";
        if (GenericData.ExecuteNoneQuery(cmd) > 0)
            result = true;
        return result;
    }

    public bool Delete(int CategoryID)
    {
        bool result = false;
        DbCommand cmd = GenericData.CreateCommand();
        cmd.CommandText = "DELETE FROM Category WHERE ID = " + CategoryID;
        if (GenericData.ExecuteNoneQuery(cmd) > 0)
            result = true;
        return result;
    }

    public bool Update(Category category)
    {
        bool result = false;
        DbCommand cmd = GenericData.CreateCommand();
        cmd.CommandText = "UPDATE Category SET CategoryName = '" + category.CategoryName + "', Description = '" + category.Description + "' WHERE ID = " + category.ID;
        if (GenericData.ExecuteNoneQuery(cmd) > 0)
            result = true;
        return result;
    }
}